import ajax from './ajax'

// 添加文章
export const reqAddArticle = (articleObj) => {
  return ajax({
    url: '/api/articles',
    method: 'post',
    data:{
      article: articleObj
    },
    headers:{
      needToken: true
    }
  })
}

// 获取文章详情
export const reqGetArticle = (slug) => {
  return ajax({
    url: `/api/articles/${slug}`,
    method: 'get',
  })
}

// 更新文章
export const reqUpdateArticle = (slug, artObj) => {
  return ajax({
    url: `/api/articles/${slug}`,
    method: 'put',
    data: {
      article:artObj
    },
    headers:{
      needToken: true
    }
  })
}

// 删除文章
export const reqDeleteArticle = (slug) => {
  return ajax({
    url: `/api/articles/${slug}`,
    method: 'delete',
    headers:{
      needToken: true
    }
  })
}

// 获取评论信息
export const reqGetComment = (slug) => {
  return ajax({
    url: `/api/articles/${slug}/comments`,
    method: 'get',
    headers:{
      needToken: true
    }
  })
}

// 删除评论信息
export const reqDeleteComment = (slug, id) => {
  return ajax({
    url: `/api/articles/${slug}/comments/${id}`,
    method: 'delete',
    headers:{
      needToken: true
    }
  })
}

// 添加评论信息
export const reqAddComment = (slug, comment) => {
  return ajax({
    url: `/api/articles/${slug}/comments`,
    method: 'post',
    data: {
      body: comment
    },
    headers:{
      needToken: true
    }
  })
}


// 收藏文章
export const reqFollowArticle = (slug) => {
  return ajax({
    url: `/api/articles/${slug}/favorite`,
    method: 'post',
    headers:{
      needToken: true
    }
  })
}

// 取消收藏文章
export const reqUnFollowArticle = (slug) => {
  return ajax({
    url: `/api/articles/${slug}/favorite`,
    method: 'delete',
    headers:{
      needToken: true
    }
  })
  return ajax({
    url: `/api/articles/${slug}/favorite`,
    method: 'delete',
    headers:{
      needToken: true
    }
  })
}